home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / SourceCode / AdobeExamples / NX_Binary / iparser.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-19  |  2.9 KB  |  129 lines

  1.  
  2. /*
  3.  * (a)  (C) 1990 by Adobe Systems Incorporated. All rights reserved.
  4.  *
  5.  * (b)  If this Sample Code is distributed as part of the Display PostScript
  6.  *    System Software Development Kit from Adobe Systems Incorporated,
  7.  *    then this copy is designated as Development Software and its use is
  8.  *    subject to the terms of the License Agreement attached to such Kit.
  9.  *
  10.  * (c)  If this Sample Code is distributed independently, then the following
  11.  *    terms apply:
  12.  *
  13.  * (d)  This file may be freely copied and redistributed as long as:
  14.  *    1) Parts (a), (d), (e) and (f) continue to be included in the file,
  15.  *    2) If the file has been modified in any way, a notice of such
  16.  *      modification is conspicuously indicated.
  17.  *
  18.  * (e)  PostScript, Display PostScript, and Adobe are registered trademarks of
  19.  *    Adobe Systems Incorporated.
  20.  * 
  21.  * (f) THE INFORMATION BELOW IS FURNISHED AS IS, IS SUBJECT TO
  22.  *    CHANGE WITHOUT NOTICE, AND SHOULD NOT BE CONSTRUED
  23.  *    AS A COMMITMENT BY ADOBE SYSTEMS INCORPORATED.
  24.  *    ADOBE SYSTEMS INCORPORATED ASSUMES NO RESPONSIBILITY
  25.  *    OR LIABILITY FOR ANY ERRORS OR INACCURACIES, MAKES NO
  26.  *    WARRANTY OF ANY KIND (EXPRESS, IMPLIED OR STATUTORY)
  27.  *    WITH RESPECT TO THIS INFORMATION, AND EXPRESSLY
  28.  *    DISCLAIMS ANY AND ALL WARRANTIES OF MERCHANTABILITY, 
  29.  *    FITNESS FOR PARTICULAR PURPOSES AND NONINFRINGEMENT
  30.  *    OF THIRD PARTY RIGHTS.
  31.  */
  32.  
  33. /*
  34. *    iparser.c
  35.  *
  36.  *    Version:    2.0
  37.  *    Author:    Ken Fromm
  38.  *    History:
  39.  *            03-07-91        Added this comment.
  40. */
  41.  
  42. #import "iinterpreter.h"
  43. #import "iparserhooks.h"
  44. #import "ierror.h"
  45. #import <objc/objc.h>
  46. #import <streams/streams.h>
  47.  
  48. extern int         yylex();
  49.  
  50. static char        *idp;
  51.  
  52. typedef  void (*VoidProc) ();
  53.  
  54. #define  NUM_PROCS    42
  55. VoidProc procs[128] = {
  56. /* 0 */     i_int, i_real,  i_string, i_literal, i_name, i_array, i_f, i_s,
  57. /* 8 */    i_clip, i_T, i_A, i_W, i_AW, i_m, i_lineto, i_L,
  58. /* 16 */    i_r, i_R, i_l, i_x, i_y, i_X, i_Y, i_c,
  59. /* 24 */    i_cp, i_w, i_g, i_j, i_d, i_miter, i_cap, i_RGB,
  60. /* 32 */    i_F, i_FF, i_DF, i_MF, i_IMASK, i_IMAGE, i_BPAGE, i_EPAGE,
  61. /* 40 */    i_REMAP, i_RECODE
  62. };
  63.  
  64.  
  65. char igetc()
  66. {
  67.     return *idp++;
  68. }
  69.  
  70. /*
  71.  *    Initializes the parsing interpreter and begins the process.
  72.  */
  73. BOOL iparse(char **dataptr)
  74. {    
  75.     BOOL     error = NO, skip = YES, done = NO;
  76.  
  77.     int        token;
  78.     
  79.     idp = *dataptr;
  80.     iinitialize();
  81.  
  82.     while (*idp != 0  && !done)
  83.     {
  84.         if (*idp == '\n')
  85.             idp++;
  86.         else if (!strncmp(idp, "%%", 2))
  87.         {
  88.             idp += 2;
  89.             if (!strncmp(idp, "Trailer", 7))
  90.                 done = YES;
  91.             else if (!strncmp(idp, "EndPageSetup", 12))
  92.                 skip = NO;
  93.             else if (!strncmp(idp, "PageTrailer", 11))
  94.                 skip = YES;
  95.  
  96.             idp = strchr(idp,'\n'); idp++;
  97.         }
  98.         else if (skip)
  99.         {
  100.             idp = strchr(idp,'\n'); idp++;
  101.         }
  102.         else
  103.         {
  104.             token = yylex();
  105.             while (token && !error)
  106.             {
  107.                 if (token <= NUM_PROCS)
  108.                 {
  109.                     (*procs[token-1]) ();
  110.                     error = iiferror();
  111.                 }
  112.                 else
  113.                     ierrorlog("Unrecognized token", &error);
  114.  
  115.                 if (!error)
  116.                     token = yylex();
  117.                 else
  118.                     ierrordisplay(token);
  119.             }
  120.         }
  121.     }
  122.     
  123.     *dataptr = idp;
  124.  
  125.     return error;
  126. }
  127.  
  128.  
  129.